package com.hankol.feature_wine_meal.viewmodel

import android.os.Handler
import androidx.lifecycle.MutableLiveData
import com.baselibrary.Constants
import com.baselibrary.base.BasicListBean
import com.baselibrary.base.mvvm.BaseViewModel
import com.hankol.feature_wine_meal.bean.CharacteristicBean
import com.hankol.feature_wine_meal.bean.FoodDetailsBean
import com.hankol.feature_wine_meal.bean.RecommendFoodBean
import com.hankol.feature_wine_meal.respository.WineMealRequestManager

/**
 * @author: 关忆北、
 * @date: 2022/6/20
 * @Des：
 */
class WineFoodViewModel : BaseViewModel() {
    val hotFoodLD: MutableLiveData<BasicListBean<FoodDetailsBean>> = MutableLiveData()
    val recommendInfoLD: MutableLiveData<BasicListBean<FoodDetailsBean>> = MutableLiveData()
    val recommendFoodLD: MutableLiveData<ArrayList<RecommendFoodBean>> = MutableLiveData()
    val characteristicLD: MutableLiveData<ArrayList<CharacteristicBean>> = MutableLiveData()
    private var mOnBannerLooperListener: OnBannerLooperListener? = null
    private var delayMillis: Long = 100 * 3
    val tHandler by lazy {
        Handler {
            mOnBannerLooperListener?.onBannerLooper()
            false
        }
    }

    fun startBannerLooper() {
        if (tHandler.hasMessages(Constants.HANDLER_WHAT_CODE)) tHandler.removeMessages(Constants.HANDLER_WHAT_CODE)
        tHandler.sendEmptyMessageDelayed(Constants.HANDLER_WHAT_CODE, delayMillis)
    }

    fun setOnBannerLooperListener(listener: OnBannerLooperListener) {
        this.mOnBannerLooperListener = listener
    }

    interface OnBannerLooperListener {
        fun onBannerLooper()
    }


    fun reqHotFood(page: Int) {
        WineMealRequestManager.getInstance().reqHotFood(10, page, hotFoodLD)
    }

    fun reqFoodRecommend() {
        WineMealRequestManager.getInstance().reqFoodRecommend(recommendFoodLD)
    }

    fun reqFoodRecommendInfo(id: Long, page: Int) {
        WineMealRequestManager.getInstance().reqRecommendInfo(id, page, recommendInfoLD)
    }

    fun reqCharacteristic() {
        WineMealRequestManager.getInstance().reqCharacteristic(characteristicLD)
    }
}